<template>
  <div>
    <!-- 头部 -->
    <LRheader :center="center" :right="right" :skip="skip"></LRheader>
    <!-- logo -->
    <div class="logo">
      <img :src="Logo" />
    </div>
    <!-- 表单 -->
    <van-form @submit="onSubmit" label-align="center">
      <van-field
        v-model="phone"
        name="phone"
        label="手机号码"
        placeholder="请输入手机号码"
        :rules="[{ required: true, message: '请填写正确的11位手机号' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="请填写密码"
        :rules="[{ required: true, message: '密码没要求' }]"
      />
      <div style="margin: 50px 140px">
        <van-button square block type="info" native-type="submit" color="#999"
          >登录</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import Logo from "../../assets/img/logo.jpg";
import LRheader from "../../components/Nav/LRheader";
import my from "../../config/modules/user";
import Vue from "vue";
import { Form, Field, Button, Icon, Toast } from "vant";
Vue.use(Toast);
Vue.use(Form);
Vue.use(Field);
Vue.use(Button);
Vue.use(Icon);
export default {
  data() {
    return {
      // 组件数据
      center: "登录",
      right: "注册",
      skip: function skip() {
        this.$router.push("/register");
      },
      //   数据库数据
      phone: "",
      password: "",
      Logo,
    };
  },
  methods: {
    //   登录
    onSubmit(values) {
      // console.log("submit", values);
      this.$http.post(my.login, values).then((res) => {
        if (res.err === 0) {
          Toast.success(res.msg);
          setTimeout(() => {
            if (this.$route.query.goto) {
              this.$router.push(this.$route.query.goto);
            } else {
              this.$router.push("/user");
            }
          }, 2000);
        } else {
          Toast.fail(res.msg);
        }
      });
    },
  },
  created() {
    // 进入该组件隐藏底部导航
    this.$store.commit("my/setIsShow", false);
    // console.log(this.$store.state.my.isShow)
  },

  //   组件注册
  components: {
    LRheader,
  },
};
</script>

<style scoped>
.nav {
  width: 100%;
  height: 50px;
  font-size: 18px;
}
.logo img {
  width: 150px;
  height: 150px;
  margin-left: 50%;
  transform: translateX(-50%);
  margin-top: 40px;
}
</style>